home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / OS Utilities / TestGestalt / TestQD / Source / TestGestalt.c
Encoding:
C/C++ Source or Header  |  1996-09-17  |  1.5 KB  |  76 lines  |  [TEXT/CWIE]

  1. #ifndef __CTYPE__
  2. #include <CType.h>
  3. #endif
  4.  
  5. #ifndef __OSUTILS__
  6. #include <OSUtils.h>
  7. #endif
  8.  
  9. #ifndef __STDIO__
  10. #include <StdIO.h>
  11. #endif
  12.  
  13. #ifndef __GESTALTEQU__
  14. #include <GestaltEqu.h>
  15. #endif
  16.  
  17. #ifndef __TYPES__
  18. #include <Types.h>
  19. #endif
  20.  
  21. #include <Traps.h>
  22.  
  23. #define    TRUE            0xFF
  24. #define    FALSE            0
  25.  
  26. Boolean TrapAvailable(short theTrap);
  27.  
  28. // check to see if a given trap is implemented. We follow IM VI-3-8.
  29. Boolean TrapAvailable(short theTrap)
  30. {
  31.     TrapType theTrapType;
  32.     short numToolboxTraps;
  33.     
  34.     if ((theTrap & 0x0800) > 0)
  35.         theTrapType = ToolTrap;
  36.     else
  37.         theTrapType = OSTrap;
  38.  
  39.     if (theTrapType == ToolTrap)
  40.     {
  41.         theTrap = theTrap & 0x07ff;
  42.         if (NGetTrapAddress(_InitGraf, ToolTrap) == NGetTrapAddress(0xaa6e, ToolTrap))
  43.             numToolboxTraps = 0x0200;
  44.         else
  45.             numToolboxTraps = 0x0400;
  46.         if (theTrap >= numToolboxTraps)
  47.             theTrap = _Unimplemented;
  48.     };
  49.  
  50.     return (NGetTrapAddress(theTrap, theTrapType) != NGetTrapAddress(_Unimplemented, ToolTrap));
  51. }
  52.  
  53.  
  54. void main()
  55. {
  56. OSErr        err;
  57. long        feature;
  58.  
  59. if (TrapAvailable(_Gestalt)) {
  60.     err = Gestalt(gestaltQuickdrawVersion, &feature);
  61.     if (!err) {
  62.         if ((feature & 0x0f00) == 0x0000)
  63.             printf ("We have Original QuickDraw version 0.%x\n", (feature & 0x00ff));
  64.         else if ((feature & 0x0f00) == 0x0100)
  65.             printf ("We have 8 Bit QuickDraw version 1.%x\n", (feature & 0x00ff));
  66.         else if ((feature & 0x0f00) == 0x0200)
  67.             printf ("We have 32 Bit QuickDraw version 2.%x\n", (feature & 0x00ff));
  68.         else
  69.             printf ("We don't have QD\n");
  70.         }
  71.     else 
  72.         printf ("Gestalt err = %i\n",err);
  73.     }
  74. else
  75.     printf ("No Gestalt\n");
  76. }